package com.briup.cms.web.controller;

import com.briup.cms.aop.Logging;
import com.briup.cms.bean.BaseConfig;
import com.briup.cms.service.IBaseConfigService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "系统配置相关接口")
@RequestMapping("/auth/config")
public class BaseConfigController {
    @Autowired
    private IBaseConfigService service;
    @ApiOperation("查询所有配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true)
    })
    @Logging
    @GetMapping("/page/query")
    public Message findAllWithPage(int pageSize, int pageNum){
        PageInfo<BaseConfig> pageInfo=service.findAllWithPage(pageNum,pageSize);
        return MessageUtil.success(pageInfo);
    }
    @ApiOperation(value = "保存配置信息", notes = "不需要传configId")
    @PostMapping("/save")
    public Message saveConfig(BaseConfig baseConfig){

        service.saveConfig(baseConfig);
        return MessageUtil.success("保存成功");
    }

    @ApiOperation(value = "更新配置")
    @Logging
    @PutMapping("/update")
    public Message updateConfig(BaseConfig baseConfig){
        service.updateConfig(baseConfig);
        return MessageUtil.success("更新成功");
    }

    @ApiOperation(value = "通过id删除配置信息")
    @ApiImplicitParam(name = "id",value = "主键",required = true)
    @Logging
    @DeleteMapping("/deleteById")
    public Message deleteById(int id){
        service.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查找当前启用的系统配置",notes = "当前最多只会有一个配置启用")
    @Logging
    @GetMapping("/current/config/yes")
    public Message currentConfigYes(){
        BaseConfig s=service.currentConfigYes();
        return MessageUtil.success(s);
    }

    @ApiOperation(value = "更新配置信息状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value ="主键" ,required = true),
            @ApiImplicitParam(name = "status",value ="状态 0-禁用 1-启用" ,required = true)
    })
    @Logging
    @PutMapping("/update/status")
    public Message changeConfigStatus(int id,int status){
        service.changeConfigStatus(id, status);
        return MessageUtil.success("状态更新成功");
    }



}

